from dataclasses import dataclass
from typing import Any


@dataclass
class SpeakerInfoData:
    """说话人信息数据模型

    包含说话人的基本信息和识别相关数据
    """

    speaker_id: str  # 说话人唯一标识
    name: str  # 说话人友好名称 (如: 说话人A, 说话人B)
    color: str  # 说话人颜色代码 (用于UI显示)
    confidence: float  # 说话人识别置信度 (0.0-1.0)
    is_new_speaker: bool  # 是否为新识别的说话人

    def to_dict(self) -> dict[str, Any]:
        """转换为字典格式，便于序列化"""
        return {
            "speaker_id": self.speaker_id,
            "name": self.name,
            "color": self.color,
            "confidence": self.confidence,
            "is_new_speaker": self.is_new_speaker,
        }

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> "SpeakerInfoData":
        """从字典创建 SpeakerInfoData 对象"""
        return cls(
            speaker_id=data["speaker_id"],
            name=data["name"],
            color=data["color"],
            confidence=data["confidence"],
            is_new_speaker=data["is_new_speaker"],
        )
